#!usr/bin/env python  
# -*- coding:utf-8 -*-
""" 
@author:robot
@file: work.py 
@version:
@time: 2024/01/14 
"""
time1 = [30, 26, 10, 35]
m1 = 3


def work(time, m):
    tmp = [0 for _ in range(m)]

    if len(time) <= m:
        return max(time)
    else:
        # 让时间重大到小排序
        time.sort(reverse=True)
        # 将m条流水线的基础工作调度安排上
        tmp[0:m] = time[0:m]
        """
        1    35
        2    30
        3    26
        """

    # 从剩余的工作时长中轮询
    for t in time[m:]:
        # 获取已经安排任务的耗时最小流水线的索引
        min_time_index = tmp.index(min(tmp))
        # 将未安排流水线任务的最长耗时的任务安排给耗时最小的流水线
        tmp[min_time_index] += t
    return max(tmp)


result = work(time1, m1)
print(result)
